<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>我的记账本</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet" />
    <style>
        label {
            font-weight: normal;
        }

        .panel-body .glyphicon-remove {
            display: none;
        }

        .panel-body:hover .glyphicon-remove {
            display: inline-block
        }
    </style>
</head>

<body>
    <div class="container">
        <div class="row">
            <div class="col-xs-12 col-lg-8 col-lg-offset-2">
                <div class="row">
                    <form class="col-xs-12 text-right" action="/logout" method="post">
                        <button class="btn btn-danger">退出登录</button>
                    </form>
                </div>
                <div class="row">
                    <h2 class="col-xs-6">记账本</h2>
                    <h2 class="col-xs-6 text-right">
                        <a href="/account/create" class="btn btn-primary">添加账单</a>
                    </h2>
                </div>
                <hr />
                <div class="accounts">
                    <% lists.forEach(list=> { %>
                        <div class="panel <%= list.type===1 ? 'panel-success' : 'panel-danger' %>">
                            <div class="panel-heading">
                                <%= moment(list.time).format('YYYY-MM-DD') %>
                            </div>
                            <div class="panel-body">
                                <div class="col-xs-6">
                                    <%= list.title %>
                                </div>
                                <div class="col-xs-2 text-center">
                                    <span class="label <%= list.type === 1 ? 'label-success' : 'label-warning' %>">
                                        <%= list.type===1 ? '收入' : '支出' %>
                                    </span>
                                </div>
                                <div class="col-xs-2 text-right">
                                    <%= list.account %> 元
                                </div>
                                <div class="col-xs-2 text-right">
                                    <a href="/account/<%= list._id %>" class="del-btn">
                                        <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
                                    </a>
                                </div>
                            </div>
                        </div>
                        <% }) %>
                </div>
            </div>
        </div>
    </div>

    <script>
        const delBtns = document.querySelectorAll('.del-btn')
        delBtns.forEach(item => {
            item.addEventListener('click', (e) => {
                if (confirm('是否删除')) {
                    return true
                } else {
                    e.preventDefault()
                }
            })
        });
    </script>
</body>

</html>